package com.itheima.day10.myStream.test7;

import java.util.ArrayList;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        ArrayList<String> al = new ArrayList<>();
        al.add("张三，23");
        al.add("李四，24");
        al.add("王五，25");

        Map<String, Integer> collect = al.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                String[] split = s.split("，");
                int age = Integer.parseInt(split[1]);
                return age >= 24;
            }
        }).collect(Collectors.toMap(
                new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return s.split("，")[0];
                    }
                },
                new Function<String, Integer>() {
                    @Override
                    public Integer apply(String s) {
                        return Integer.parseInt(s.split("，")[1]);
                    }
                }
        ));
        System.out.println(collect);

        al.stream().filter(
                s -> {
                    return Integer.parseInt(s.split("，")[1]) >= 24;
                }
        ).collect(Collectors.toMap(
                new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return s.split("，")[0];
                    }
                },
                new Function<String, Integer>() {
                    @Override
                    public Integer apply(String s) {
                        return Integer.parseInt(s.split("，")[1]);
                    }
                }
        ));


        al.stream().filter(
                s -> Integer.parseInt(s.split("，")[1]) >= 24
        ).collect(Collectors.toMap(
                s -> s.split("，")[0],
                s -> Integer.parseInt(s.split("，")[1])
        ));


    }
}
